package com.example.service.Impl;

import com.example.Constants.SystemConstants;
import com.example.domain.ResponseResult;
import com.example.domain.entity.LoginUser;
import com.example.domain.entity.User;
import com.example.domain.vo.InitUserVo;
import com.example.mapper.InitMapper;
import com.example.service.InitService;
import com.example.utils.BeanCopyUtils;
import com.example.utils.SecurityUtils;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
@Service
public class InitServiceImpl implements InitService {
    @Resource
    private InitMapper initMapper;
    @Override
    public ResponseResult init() {
        User user = SecurityUtils.getLoginUser().getUser();
        String userId = user.getId();
        InitUserVo initUserVos = initMapper.init(userId);
        List<String> perms = null;
        if (SystemConstants.ADMIN.equals(user.getAuthority())) {
            //当前用户为超级管理员
            perms = initMapper.selectAllMenuPermS();
        }else {
            //当前用户为非超级管理员
            perms = initMapper.selectMenuPremsByUserId(userId);
        }
        initUserVos.setPerms(perms);
        HashMap<String, InitUserVo> initUserVoHashMap = new HashMap<>();
        initUserVoHashMap.put("userInfo",initUserVos);
        return ResponseResult.okResult(initUserVoHashMap);
    }
}
